package com.maslyk.invitation.converter;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.ConverterException;

import com.maslyk.invitation.page.Utils;

/**
 *
 * @author kris
 */
public class FormatedText implements Converter
{

    public Object getAsObject(FacesContext arg0, UIComponent arg1, String arg2) throws ConverterException
    {
        return arg2;
    }

    public String getAsString(FacesContext arg0, UIComponent arg1, Object arg2) throws ConverterException
    {
    	if(arg2 == null)
    		return null;
    	
        if(arg2 instanceof String)
            return Utils.encodeString((String)arg2);
        else if (arg2 instanceof StringBuffer)
            return Utils.encodeString(((StringBuffer)arg2).toString());
        
        return "Invitation: Error conversion "+arg2.getClass().getName()+" to String";
    }
}
